Showing posts with label Python Language. Show all posts
Showing posts with label Python Language. Show all posts

Monday, April 6, 2015

[Pyinstaller] Solution about requests.packages.chardet.sys no module named error



If you use pyinstaller & requests module. And If you get error no module named requests.packages.chardet.sys

You have to check requests module's version.

Go to concole type following sentence.

1. python [enter]
2. import requests [enter]
3. requests.__version__ [enter]

Now you can see requests' version.
Is version 2.6.0?
Oh my god. Yes! Find it!

Please uninstall that.
with this command

pip uninstall requests

And you have to install 2.5.0

pip install requests==2.5.0

Then there is no error!!! :) Do this!!

Thursday, February 5, 2015

[Python] Using SSH with Python

  Do you want to use ssh in python? I needed to do! I use server hosting, but there is no authority for using crontab. Beacause of that I need ssh in python! In my server I can use crontab so I can write my script using ssh with python. After that I registered that script in my crontab. Now I can fulfill my purpose through that script.

  We need paramiko module for using ssh in python. Let's install paramiko

$ pip install paramiko

  Then we will get paramiko.

  For now, write python code!

import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("yourserver.com",username='your_id',password='your_passwords')
stdin, stdout, stderr = ssh.exec_command("command what you want to execute");

  Can you understand this? Import paramiko module and create paramiko SSHClient object with name ssh. And set AutoAddPolicy. When you access some server with ssh first time. You can see the message "do you trust this host and use connection?" like that. AutoAddPolicy is for that, it will trust host automatically. Next, you have to access to a server computer with connection function. After that you can execute shell command with exec_command function.

  If you need to print out result. Use "stdout.readlines()"

  Did you execute this? Let's do this!

Monday, February 2, 2015

[Python] Where is my python? How can I find python path?

Do you want to find your python path? (It doesn't matter what is your os).


Step 01. Open your terminal(command line prompt) type python.
Then you get python REPL.

Step 02. Type import sys. Press Enter key. You can use sys module.

Step 03. Type sys.executable. Press Enter key. Yeah! Finally you get python path!! Did you see that? '/home/bin/python'? That is my python path. You get same thing or other thing.

Go ahead!!!